package com.rr.learningdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author RR
 * @date 2021/5/17 23:29
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("a")
                .apiInfo(getApiInfo())
                .select()
                //可选择按包、按类注解、方法注解、全选、全不选进行过滤
                .apis(RequestHandlerSelectors.basePackage("com"))
                //按路径进行过滤
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("b")
                .apiInfo(getApiInfo())
                .select()
                //可选择按包、按类注解、方法注解、全选、全不选进行过滤
                .apis(RequestHandlerSelectors.basePackage("com"))
                //按路径进行过滤
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo getApiInfo(){
        return new ApiInfo(
                "呵呵",
                "Api Documentation",
                "1.1",
                "urn:tos",
                getContact(),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }

    private Contact getContact(){
        return new Contact("", "", "");
    }

}
